home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-04 | 10.6 KB | 149 lines | [TEXT/KAHL] |
-
- //• Subject: Display a file program
- //• Message-ID: <1701@uw-beaver>
- //• Date: Wed, 6 Nov 85 22:18:16 MST
- //• Date-Received: Fri, 8 Nov 85 02:05:35 MST
- //• Sender: daemon@uw-beaver
- //• Organization: U of Washington Computer Science
- //• Lines: 372
-
- //• From: kangaro!milo@Purdue.EDU
-
- //• This is a little program I whipped up in Megamax C that will
- //• display any Mac file of type TEXT. It is very handy for looking
- //• at text files you have downloaded from a BBS without having to
- //• load a text editor. The program loads in about 4 seconds and
- //• supports standard Mac desk accessorys...etc.
-
- //• Let me know if you have any problems with the program...the
- //• source follows...
-
- //• Greg Corson
- //• UUCP: {ihnp4 | ucbvax}!pur-ee!kangaro!milo
- //• ARPA: pur-ee!kangaro!milo@Purdue.ARPA
- //• EDU: kangaro!milo@ee.Purdue.EDU
- //• Or call my BBS at (219) 277-5825
-
- //• This sample program allows a user to open a file and print
- //• it's contents to a window on the Mac screen. To give the
- //• compiled program an Icon copy the resources from Display.rsrc
- //• (use Rmover or Resource Editor) and paste them into the
- //• compiled file. Then use SetFile to change the creator name of
- //• the compiled file to DFIL and set the bundle bit. When you
- //• return to the finder the program icon should have an icon.
-
- //• By Greg Corson
- //• 19141 Summers Drive
- //• South Bend, IN 46637
- //• (219) 272-2136
- //• UUCP: {ihnp4 | ucbvax}!pur-ee!kangaro!milo
- //• ARPA: pur-ee!kangaro!milo@Purdue.ARPA
- //• EDU: kangaro!milo@ee.Purdue.EDU
- //• Or call my BBS at (219) 277-5825
-
- #include <packages.h>
-
- #define lastMenu 4
- #define appleMenu 1
- #define fileMenu 256
- #define editMenu 257
- #define stopMenu 258
-
- RgnHandle updateRgn;
- MenuHandle myMenus[lastMenu+1];
- Rect screenRect, dragRect, pRect;
- Boolean doneFlag, temp;
- EventRecord myEvent;
- short code, refNum;
- WindowRecord wRecord;
- WindowPtr myWindow, whichWindow;
- GrafPtr temPort;
- short theMenu, theItem;
- short fileOpen, wide, fd1;
- long count;
- char tempBuf[32];
-
- void Center (char *str);
-
- //•---------------------------------------------------------------------------*/
- //• This subroutine processes commands from the menu bar, where
- //• theMenu is the menu ID, theItem is the item number in the menu.
-
- void DoCommand (long mSelect)
- {
- short theMenu = HiWord(mSelect);
- short theItem = LoWord(mSelect);
- char name[256];
- SFReply rep;
- SFTypeList typeList;
- short i;
-
- Point openP = { 100, 60 };
-
- //• Switch to decide what menu the cursor is in.
- switch (theMenu)
- {
- //• Mouse down in apple menu.
- case appleMenu:
- //• Item one is the "about Display a file" box.
- if (theItem == 1)
- {
- TextFont (systemFont);
- TextSize (12);
- EraseRect (&pRect);
- MoveTo (pRect.left, pRect.top+70);
- Center ((char*) "\pDisplay a file program");
- Center ((char*) "\pCopyright 1985 by Greg Corson");
- Center ((char*) "\pKangaroo Koncepts, Inc.");
- Center ((char*) "\p19141 Summers Drive");
- Center ((char*) "\pSouth Bend, IN 46637");
- Center ((char*) "\p1(219) 277-5306");
- TextFont (monaco);
- TextSize (9);
- Move (0, -3);
- Center ((char*) "\pFeel free to give this program away to all your friends.");
- Center ((char*) "\pIt should NOT be sold for profit. Be sure to try our");
- Center ((char*) "\pComputer Based Communications System \"The Connection\"");
- Center ((char*) "\pFree demo line (219) 277-5825 available 24 hours at 300 or");
- Center ((char*) "\p1200 baud. Be sure to look at the \"MacTech\" special");
- Center ((char*) "\pinterest group for information of interest to Mac");
- Center ((char*) "\pprogrammers and the \"macintosh\" SIG for general info.");
- Center ((char*) "\pAnother old program \"brought back from the dead\"");
- Center ((char*) "\pby Ken Long, at itty bitty bytes™");
- Pretty ();
- MoveTo (pRect.left + 1, pRect.bottom - 2);
- }
- //• The rest of the items are desk accessorys.
- else
- {
- GetItem (myMenus[1], theItem, name);
- refNum = OpenDeskAcc (name);
- SetPort (myWindow);
- }
- break;
-
- case fileMenu:
- //• Mouse down in file menu.
- switch (theItem)
- {
- case 1: //• Open file.
- typeList[0] = 'TEXT';
- SFGetFile (openP, "\p", 0L, 1, typeList, 0L, &rep);
- if (rep.good)
- {
- //• Doesn't mess with DisableItem, etc.
- if (fileOpen)
- {
- FSClose (fd1);
- fileOpen = false;
- }
- if (FSOpen (rep.fName, rep.vRefNum, &fd1) == noErr)
- {
- ScrollRect (&pRect, 0, -11, updateRgn);
- fileOpen = true;
- }
- }
- break;
-
- //• Close file.
-